<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.io.*,java.util.List,java.util.ArrayList,domain.User"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+
					request.getServerName()+":"+
					request.getServerPort()+path+"/";
//	out.print(basePath);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<base href="<%=basePath %>">
    <title></title>
    <meta charset="UTF-8">
    
    <!-- servlet跳转到jsp
    	请求的发起方：servlet
    		请求的路径：music_project/sys/servlet
    		绝对路径定位/css/js
    	传统的请求发起方是html页面
    	
    	request可以获取到请求对象的路径信息
    	
    	base:将这个页面的路径定位到basepath，
    	相对路径相对的就是basePath:music_project
    	
     -->
    
    <link rel="stylesheet" type="text/css" href="sys/Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="sys/Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="sys/Css/style.css" />
    <script type="text/javascript" src="sys/Js/jquery.js"></script>
    <script type="text/javascript" src="sys/Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="sys/Js/bootstrap.js"></script>
    <script type="text/javascript" src="sys/Js/ckform.js"></script>
    <script type="text/javascript" src="sys/Js/common.js"></script>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>
<form class="form-inline definewidth m20" action="sys/UserServlet" method="Post">    
    用户名称：<input type="hidden" name="type" value="search">
    <input type="text" name="username" id="username"class="abc input-default" placeholder="" value="">&nbsp;&nbsp;  
    <button type="submit" class="btn btn-primary">查询</button>&nbsp;&nbsp; 
    <button type="button" class="btn btn-success" id="addnew">新增用户</button>
</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th>用户id</th>
        <th>用户姓名</th>
        <th>用户性别</th>
        <th>邮件地址</th>
        <th>最后登录时间</th>
        <th>操作</th>
    </tr>
    </thead>
    
    <c:forEach items="${page.list}" var="user">
    	<tr>
    		<th>${user.user_id }</th>
    		<th>${user.user_name }</th>
    		<th>${user.user_gender }</th>
    		<th>${user.user_mail }</th>
    		<th><%=new Date() %></th>
    		<td>
                <a href="sys/UserServlet?id=${user.user_id }&type=findById">编辑</a> 
                <a href="sys/UserServlet?id=${user.user_id }&type=del">删除</a>               
            </td>
    	</tr>
    </c:forEach>

    
    
 <%--    <!-- list中有多少个users就会有多少个 tr -->
    <% 
    	List<User> list = (List<User>)request.getAttribute("list");
    	for(User user:list){
    %>
	     <tr>
            <td><%=user.getUser_id() %></td>
            <td><%=user.getUser_name() %></td>
            <td><%=user.getUser_mail() %></td>
            <td><%=new Date() %></td>
            <td>
                <a href="sys/UserServlet?id=<%=user.getUser_id() %>&type=findById">编辑</a> 
                <a href="sys/UserServlet?id=<%=user.getUser_id() %>&type=del">删除</a>               
            </td>
        </tr>	
     <%} %> --%>
</table>
<p>
	共 ${page.totalPage }页/共 ${page.totalRecord }条记录&nbsp;&nbsp;
	<a href="studentServlet?method=find&pageNum=1&pageSize=5">首页</a>&nbsp;&nbsp;
	<a href="studentServlet?method=find&pageNum=${page.totalPage }&pageSize=5">末页</a>&nbsp;&nbsp;
	
	<c:forEach var="i" begin="${page.start }" end="${page.end }" step="1">
		<c:choose>
			<c:when test="${i == page.pageNum }">${i }</c:when>
			<c:otherwise><a href="studentServlet?method=find&pageNum=${i }&pageSize=5">${i }</a></c:otherwise>
		</c:choose>
	</c:forEach>

</p>


</body>
</html>
<script>
    $(function () {
		$('#addnew').click(function(){
			$.ajax({
				type: "post",
				url: "token"
			});
			window.location.href="sys/User/add.jsp";
		 });
    });

	function del(id)
	{
		if(confirm("确定要删除吗？"))
		{
			var url = "index.html";
			window.location.href=url;		
		}
	}
</script>